<?php
//------------------------------------//
// iJobs - Job Listing Software       //
// Version: 1.0.0 Alpha 1             //
// Author: RIXWIL Software            //
// Website: http://www.rixwil.com     //
//------------------------------------//
// index.php - Core File              //
//------------------------------------//

ob_start();

// Lets Get Configured //
include "../includes/config.php";

// Lets Load My Header //
include "../templates/skin_cp/header.tpl";

// Lets Do Some Things

switch($_GET['do']) { 
	case 'general':
		$sql = "UPDATE system SET SystemEnabled = '".$_REQUEST['systemenabled']."', SystemOffMsg = '".$_REQUEST['systemoffmsg']."', SystemLang = '".$_REQUEST['language']."' WHERE id='1'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Settings Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=general' />";
	break;
	case 'edittitle':
		$id = $_GET['edittitle'];
		$sql = "UPDATE system SET SystemTitle = '".$_REQUEST['edittitle']."' WHERE id='1'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Settings Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=edittitle' />";
	break;
	case 'editabout':
		$id = $_GET['editabout'];
		$sql = "UPDATE system SET SystemAbout = '".$_REQUEST['editabout']."' WHERE id='1'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Settings Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=editabout' />";
	break;
	case 'editcontacts':
		$sql = "UPDATE system SET SystemContact = '".$_REQUEST['contact']."', ContactNumber = '".$_REQUEST['contactnumber']."', ContactEmail = '".$_REQUEST['contactemail']."' WHERE id='1'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Settings Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=editcontacts' />";
	break;
	case 'updatenotes':
		$id = $_GET['dashboardnotes'];
		$sql = "UPDATE system SET SystemNotes = '".$_REQUEST['dashboardnotes']."' WHERE id='1'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Settings Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php' />";
	break;
	case 'editjob':
		$sql = "UPDATE jobs SET Employer = '".$_REQUEST['employer']."', JobTitle = '".$_REQUEST['jobtitle']."', ContactNumber = '".$_REQUEST['contactnumber']."', ContactEmail = '".$_REQUEST['contactemail']."', Wage = '".$_REQUEST['wage']."', Hours = '".$_REQUEST['hours']."', Description = '".$_REQUEST['description']."' WHERE JobID='".$_REQUEST['jobid']."'";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Job Updated, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=viewjobs' />";
	break;
	case 'addjob':
		$sql = "INSERT INTO `jobs` (`JobID`, `JobTitle`, `Employer`, `ContactNumber`, `ContactEmail`, `Wage`, `Hours`, `Description`, `Timestamp`)
VALUES (
NULL , '".$_REQUEST['jobtitle']."', '".$_REQUEST['employer']."', '".$_REQUEST['contactnumber']."', '".$_REQUEST['contactemail']."', '".$_REQUEST['wage']."', '".$_REQUEST['hours']."', '".$_REQUEST['description']."', CURRENT_TIMESTAMP);";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Job Added, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=viewjobs' />";
	break;
	case 'approvejob':
		$sql = "INSERT INTO `jobs` (`JobID`, `JobTitle`, `Employer`, `ContactNumber`, `ContactEmail`, `Wage`, `Hours`, `Description`, `Timestamp`)
VALUES (
NULL , '".$_REQUEST['jobtitle']."', '".$_REQUEST['employer']."', '".$_REQUEST['contactnumber']."', '".$_REQUEST['contactemail']."', '".$_REQUEST['wage']."', '".$_REQUEST['hours']."', '".$_REQUEST['description']."', CURRENT_TIMESTAMP);";
		$result = mysql_query($sql);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Job Approved, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=pendingjobs' />";
	break;
	case 'deletejob':
		$id = $_GET['id'];
		$query = "DELETE FROM jobs WHERE JobID = ('$id')";
		$result = mysql_query($query);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Job Deleted, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=viewjobs' />";
	break;
	case 'deletependingjob':
		$id = $_GET['id'];
		$query = "DELETE FROM pendingjobs WHERE id = ('$id')";
		$result = mysql_query($query);
			if (!$result) {
    			die('Invalid query: ' . mysql_error());
			}
		echo "<div class='path'><strong>Job Deleted, You are being redirected!</strong></div>";
		echo "<meta http-equiv='refresh' content='5;URL=index.php?module=pendingjobs' />";
	break;
	case 'newlang':
      $allowed_filetypes = array('.xml');
      $max_filesize = 524288;
      $upload_path = '../includes/lang/';
 
   $filename = $_FILES['userfile']['name'];
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
 
   if(!in_array($ext,$allowed_filetypes))
      die('<div class="path"><strong>The file you attempted to upload is not allowed.</strong></div><meta http-equiv="refresh" content="5;URL=index.php?module=general#newlang" />');
 
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('<div class="path"><strong>The file you attempted to upload is too large.</strong></div><meta http-equiv="refresh" content="5;URL=index.php?module=general#newlang" />');
 
   if(!is_writable($upload_path))
      die('<div class="path"><strong>You cannot upload to the specified directory, please CHMOD it to 777.</strong></div><meta http-equiv="refresh" content="5;URL=index.php?module=general#newlang" />');
 
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo '<div class="path"><strong>The Language has been uploaded, You are being redirected!</strong></div><meta http-equiv="refresh" content="5;URL=index.php?module=general" />';
      else
         echo '<div class="path"><strong>There was an error during the language file, You are being redirected!</strong></div><meta http-equiv="refresh" content="5;URL=index.php?module=general" />';
	break;
}

// Lets Structure My Links //

switch($_GET['module']) { 
	case 'general':
		include('../templates/skin_cp/general.tpl');
	break;
	case 'edittitle':
		include('../templates/skin_cp/edittitle.tpl');
	break;
	case 'editabout':
		include('../templates/skin_cp/editabout.tpl');
	break;
	case 'editcontacts':
		include('../templates/skin_cp/editcontacts.tpl');
	break;
	case 'checkupdates':
		include('../templates/skin_cp/checkupdates.tpl');
	break;
	case 'viewjobs':
		include('../templates/skin_cp/viewjobs.tpl');
	break;
	case 'addnewjob':
		include('../templates/skin_cp/addjob.tpl');
	break;
	case 'pendingjobs':
		include('../templates/skin_cp/pendingjobs.tpl');
	break;
	default:
		include('../templates/skin_cp/index.tpl');
	break;
}

// Now thats done, lets finish with a footer //
include "../templates/skin_cp/footer.tpl";

ob_flush();

//---------------------------------------------//
// Just a little copyright notice              //
//=============================================//
// iJobs is free to download and use, we only  //
// ask for one thing, and thats to keep all    //
// copyright and powered by lines intact       //
//---------------------------------------------//
?>